<?php
    // 查询 lunbo 表
    function get_lunbo_data(){
        $result = mysql_query("SELECT * FROM lunbo");
  
        $results = array();
        while ($row = mysql_fetch_assoc($result)) {
            $results[] = $row;
        }

        foreach ($results as $key => $value) {
            $zhaopinData = get_recruit_data_by_recruit_id($value["recruit_id"]);
            
            unset($results[$key]["recruit_id"]);
    
            $results[$key]["recruit_id"] = $zhaopinData;
        }

        
    
        $arrData = createJsonData($results);
        
        echo json_encode($arrData);
    }


    // 轮播图 图片上传接口
    function upload_lunbo_img($lunbo_id){
        // <input type="file" name="uploadFile" id="">
        $imgPath = shangchuan();
        if ($imgPath == "") {
            error_return("上传失败");
        } else {
            mysql_query("update lunbo set image='$imgPath' 
            where lunbo_id='$lunbo_id'");
            success_return($imgPath);
        }
    }

    // 添加 lunbo 数据
    function insert_lunbo_data(){
        $lunbo_id = time() * 3;
        mysql_query("insert into lunbo 
        (lunbo_id , title , recruit_id)  
        values 
        ('$lunbo_id' , '$_POST[title]' , 
        '$_POST[recruit_id]')");

        upload_lunbo_img($lunbo_id);
        
        
    }

    // 轮播图批量删除接口
    function delete_many_lunbo() {

        $sqlStr = "delete from lunbo where lunbo_id in (";

        foreach (json_decode($_POST["lunbo_ids"] , true) as $value) {
            $sqlStr = $sqlStr."'".$value."',";
        }

        $sqlStr = substr($sqlStr,0,strlen($sqlStr)-1).")"; 

        $result = mysql_query($sqlStr);

        if ($result >= 1) {
            success_return("删除成功");
        } else {
            error_return("删除失败");
        }
    }

    // 改变 轮播图 是否显示状态 
    function change_lunbo_status() {
        mysql_query("update lunbo set statis = '$_POST[status]' 
        where 
        lunbo_id='$_POST[lunbo_id]'");
    }

    // 删除 lunbo 数据
    function delete_lunbo_data(){
        mysql_query("delete from lunbo where lunbo_id='$_POST[lunbo_id]'");
    }



?>